<?php

namespace App\Models;


use Illuminate\Database\Eloquent\Model;
use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;

class User extends Model
{

    use Notifiable,HasApiTokens;

    public function workshop()
    {
        return $this->belongsTo(Workshop::class);
    }

    public function getRoleIdsAttribute($role_ids)
    {
        return json_decode($role_ids, true);
    }

    public function setRoleIdsAttribute($role_ids)
    {

        if (in_array(M01_ID, $role_ids)) {
            $this->attributes['is_technician'] = DEFAULT_TRUE;
        } else {
            $this->attributes['is_technician'] = DEFAULT_FALSE;
        }

        $this->attributes['role_ids'] = json_encode($role_ids);
    }
}
